package com.umeox.mediaplayer

import android.content.Context
import android.media.AudioManager
import android.os.Bundle
import com.umeox.moto.watch.themes.app.ThemeAppCompatActivity
import com.umeox.moto.watch.themes.widget.Slider

class VolumeActivity :ThemeAppCompatActivity(), Slider.OnPositionChangeListener {

    private lateinit var slVolume: Slider
    private var mMediaCurrentVolume = 0
    private var mMediaMaxVolume = 0
    private var mAudioManager: AudioManager? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_volume_settings)
        slVolume = findViewById(R.id.slVolume)
        mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
        mMediaMaxVolume = mAudioManager!!.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
        mMediaCurrentVolume = mAudioManager!!.getStreamVolume(AudioManager.STREAM_MUSIC)
        slVolume.setValueRange(0, mMediaMaxVolume, false)
        slVolume.setValue(mMediaCurrentVolume.toFloat(), true)
        slVolume.setOnPositionChangeListener(this)
        slVolume.onchangeState(true)

    }

    override fun onPositionChanged(
        view: Slider?,
        fromUser: Boolean,
        oldPos: Float,
        newPos: Float,
        oldValue: Int,
        newValue: Int
    ) {

        mAudioManager!!.setStreamVolume(
            AudioManager.STREAM_MUSIC,
            newValue,
            AudioManager.FLAG_PLAY_SOUND or AudioManager.FLAG_VIBRATE
        )
    }
}